package rule

import "strings"

var (
	acceptedMap = map[string]struct{}{"yes": {}, "no": {}, "1": {}}
)

func init() {
	Register(&acceptedRule{})
}

type acceptedRule struct{}

func (a *acceptedRule) Name() string {
	return "accepted"
}

func (a *acceptedRule) Check(in *RuleInput) (err error) {

	if v, ok := in.Value.(int); ok && v == 1 {
		return
	}

	if v, ok := in.Value.(string); ok {
		if _, ok1 := acceptedMap[strings.ToLower(v)]; ok1 {
			return
		}
	}
	return in.Error()
}
